﻿using AutoMapper;
using AutoMapper.Mappers;
using Core.Dtos;
using Core.Domain;
using Core.Messages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Mappers
{
    public class ListTypeConverter<TSource, TDest> : ITypeConverter<QueryResponse<TSource>, QueryResponse<TDest>>
    {
        public QueryResponse<TDest> Convert(ResolutionContext context)
        {
            QueryResponse<TSource> source = (QueryResponse<TSource>)context.SourceValue;
            QueryResponse<TDest> dest = new QueryResponse<TDest>();
            dest.PageNumber = source.PageNumber;
            dest.PageSize = source.PageCount;
            dest.TotalItemCount = source.TotalItemCount;            
            dest.List = AutoMapper.Mapper.Map<IList<TSource>, IList<TDest>>(source.List);
            return dest;
        }
    }
}
